import 'dart:convert';

import 'package:flutter/material.dart';
import '../pages/common.dart';
// 保存状态存储
import 'package:shared_preferences/shared_preferences.dart';

class Tab1 extends StatelessWidget {
  const Tab1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Image.asset(
          'assets/img/logo.png',
          fit: BoxFit.cover,
          width: 84,
        ),
        automaticallyImplyLeading: false,
        centerTitle: true,
      ),
      body: Container(
        child: Column(
          children: [
            OnButton(
                name: "退出登录",
                callBack: () async {
                  final prefs = await SharedPreferences.getInstance();
                  final result = await prefs.clear();
                  print(result);
                  if (result) {
                    print('退出登录');
                    Navigator.pushNamed(context, '/login');
                  }
                }),
            OnButton(
                name: "获取登录信息",
                callBack: () async {
                  SharedPreferences prefs =
                      await SharedPreferences.getInstance();
                  String? loginInfo = prefs.getString("loginInfo");
                  print(loginInfo);

                  Map<String, dynamic> user = jsonDecode(loginInfo!);
                  print(user);
                  print(user['token']);
                  print(user['data']['id']);

                  // Map<String, dynamic> userdata = jsonEncode(user['data']!);
                  // print(userdata);
                })
          ],
        ),
      ),
    );
  }
}
